package uicgas.pump.commands;

import uicgas.communication.Communication;
import uicgas.globaldata.ControlMessage;
import uicgas.globaldata.MessagePayload;
import uicgas.globaldata.Messages;
import uicgas.globaldata.PumpState;
import uicgas.globaldata.SelfAnnouncement;
import uicgas.globaldata.States;
import uicgas.pump.PumpLogic;

/**
 * Announce current state of this client
 * 
 * @author Hong Wang
 *
 */
public class AnnounceState extends AbstractRemoteCommand
{
	private SelfAnnouncement announcementOfRegister = null;

	public AnnounceState(PumpLogic pumpLogic, Communication communication,
			MessagePayload payload)
	{
		super(pumpLogic, communication);
		this.announcementOfRegister = (SelfAnnouncement) payload;
	}

	@Override
	public void executeRemoteCommand()
	{
		States currentState = pumpLogic.getCurrentState();
		PumpState pumpState = new PumpState(currentState, pumpLogic.getID());
		pumpState.setDestinationID(announcementOfRegister.getID());
		communication.sendData(new ControlMessage(Messages.STATEREPLY,
				pumpState));
	}
}
